package xdu.lz.stage7_jucCollection.copyonwriteArrayList;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Created at 2019/10/30 0030 上午 11:03
 * --
 */
public class COWArrayList {
    public static void main(String[] args) {
        test1(new ArrayList<>());
        test1(new CopyOnWriteArrayList<>());
    }

    private static void test1(List<Integer> list){
        System.out.println("list = " + list.getClass());
        long time1 = System.nanoTime();
        for (int i = 0; i < 10_0000; i++) {
            list.add(i);
        }
        long time2 = System.nanoTime();
        for (int i = 0; i < list.size(); i++) {
            list.get(i);
        }
        long time3 = System.nanoTime();
        System.out.println("write:"+(time2 - time1)/1000_000);
        System.out.println("read:"+(time3 - time2)/1000_000);

    }
}
